package socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class LengthCalculator extends Thread {
    private Socket socket;

    public LengthCalculator(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            OutputStream outputStream = socket.getOutputStream();
            InputStream inputStream = socket.getInputStream();
            int ch = 0;
            byte[] bytes = new byte[1024];
            ch = inputStream.read(bytes);
            String content = new String(bytes, 0, ch);
            System.out.println(content);
            outputStream.write(String.valueOf(content.length()).getBytes());

            inputStream.close();
            outputStream.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
